{% load i18n %}
$("tr:gt(0)", $('.repo-list')).unbind().hover(
    function() {
        if ($('.repo-del-cfm:visible', $('.repo-list')).length == 0) {
            $(this).addClass('hl');
            $(this).find('.op-icon, .op').removeClass('vh');
        }   
    },  
    function() {
        if ($('.repo-del-cfm:visible', $('.repo-list')).length == 0) {
            $(this).find('.op-icon, .op').addClass('vh');
            $(this).removeClass('hl');
        }   
    }   
);

$('.repo-delete-btn').click(function() {
    var op = $(this);
    var cont = op.parent().css({'position': 'relative'}),
        cfm;
    
    // only show 1 popup each time.
    $('.repo-del-cfm', op.parents('table')).addClass('hide');

    if (cont.find('.repo-del-cfm').length == 1) {
        cfm = cont.find('.repo-del-cfm');
    } else {
        cfm = $('#repo-del-cfm-popup').clone().removeAttr('id'); 
        cont.append(cfm);
        cfm.css({'left': op.position().left, 'top': op.position().top + op.height() + 2, 'width':202});
    }
    var con = $('.con', cfm);
    con.html(con.html().replace('%(lib_name)s', '<span class="op-target">' + cfm.parents('td').attr('data-name') + '</span>'));
    cfm.removeClass('hide');
    $('.no',cfm).click(function() {
        cfm.addClass('hide');
    });
    $('.yes', cfm).click(function() {
        $.ajax({
        url: '{{ SITE_ROOT }}ajax/repo/' + op.parents('td').data('id') + '/remove/',
        dataType: 'json',
        success: function(data) {
            op.parents('tr').remove();
            feedback("{% trans "Delete succeeded." %}", 'success');
        },  
        error: ajaxErrorHandler
        }); 
    }); 
    return false; // for <a> in some pages
}); 
